<!DOCTYPE html>
<html>

<head>
	<meta charset=utf-8>
	<title>Effekseer For Cocos2d-x</title>
	<link href="base.css" rel="stylesheet" type="text/css" />
</head>

<body>
	<div class="main">
		<h1>Effekseer For Cocos2d-x</h1>
		
		<h2>Overview</h2>

		<p>
        Effekseer is a tool that makes it easy to create beautiful particle effects. This library allows you to play particle effects created with Effekseer on Cocos2d-x.
        This document describes cooperation between Effekseer and Cocos2d-x.
        The library consists of multiple source code files, and you can install it by adding the source code file to the project of Cocos2d-x.
		</p>

		<p>
		The corresponding environment is as follows.
		</p>

		<table>
			<tr>
				<td>Windows</td>
				<td>OK</td>
			</tr>

			<tr>
				<td>Mac OS X</td>
				<td>OK</td>
			</tr>

			<tr>
				<td>Linux</td>
				<td>Unknown</td>
			</tr>

			<tr>
				<td>iOS</td>
				<td>OK</td>
			</tr>

			<tr>
				<td>Android</td>
				<td>OK</td>
			</tr>

			<tr>
				<td>WindowsPhone</td>
				<td>Unknown</td>
			</tr>

		</table>

		<div align="Center">
			<img src="Top.png">
		</div>

		<h2>Important</h2>
		<p>
		Cocos2d-x Effekseer branch is required to use it with Cocos2d-x v4 and MacOSX
		</p>

		<a href="https://github.com/effekseer/cocos2d-x/tree/cocos2d-x-effekseer">Cocos2d-x Effekseer branch</a>

		<h2>Installation method (Version4)</h2>
		<p>
		Please copy Players/Cocos2d-x_v4 to the project of Cocos 2d-x.
		</p>

		<p>
		Add codes int CMakeLists.txt as follows.
		</p>

<pre>
add_subdirectory(Cocos2d-x_v4)
target_link_libraries(${APP_NAME} EffekseerForCocos2d-x)
</pre>

		<h2>Installation method (Version3)</h2>
		<p>
		<b>Players/Cocos2d-x_v3</b>following files to the directory exists.
		</p>

<ul>
<li>Effekseer.cpp</li>
<li>Effekseer.h</li>
<li>EffekseerNative.cpp</li>
<li>EffekseerNative.h</li>
<li>EffekseerRendererNative.cpp</li>
<li>EffekseerRendererNative.h</li>
</ul>

		<p>
		Please copy these files to the project of Cocos 2d - x and add it to compile them.
		</p>


		<h2>How to use</h2>

<p>
        In <b>Samples/</b> directory in Cocos2d-x is a sample to play the particle effects of Effekseer. Since this document only explains basic usage, please see the sample for detailed usage.
</p>

<p>
    These samples, for this library is not included, please copy the library of files in each sample of <b>Classes/Effekseer</b> directory.
    <b>copyEffekseerFiles.txt</b> file exists in the directory to copy to as the marker of the directory to which the library is copied.
</p>

<h3>About files that can be played</h3>

<p>
    Only files saved by Effekseer's standard output can be played. The saved file contains the relative path from Effekseer's project to the image. For that reason, you need to place the image while keeping the relative path from the file saved in standard output to the image.
</p>

<h3>Basic playback</h3>

<p>
Play effects files saved with Effekseer's standard output with Cocos2d-x. For more information, please look at the source code that is stored in the <b>Samples/Simple/</b>.
</p>

<br>

<p>
Include EffekseerForCocos2d-x.h(Version4) or Effekseer.h(Version3).
</p>

<pre>
#if COCOS2D_VERSION >= 0x00040000
#include "EffekseerForCocos2d-x.h"
#else
#include "Effekseer/Effekseer.h"
#endif
</pre>
<br>

<p>
Add efk::EffectManager* to the member variable of the class that inherits cocos2d::Scene or cocos2d::Layer.
</p>

<pre>
class HelloWorld : public cocos2d::Scene /* Layer */ {
efk::EffectManager* manager = nullptr;
...
</pre>
<br>

<p>
Create an instance of efk::EffectManager*.
</p>

<pre>
manager = efk::EffectManager::create(Director::getInstance()->getVisibleSize());
</pre>
<br>

<p>
Load the effect file.
</p>

<pre>
auto effect = efk::Effect::create("Laser01.efk");
</pre>
<br>

<p>
Generate the emitter, set the parameters and add it to the scene.
</p>

<pre>
auto emitter = efk::EffectEmitter::create(manager);
emitter->setEffect(effect);
emitter->setPlayOnEnter(true);

emitter->setPosition(Vec2(300, 300));
emitter->setScale(20);
this->addChild(emitter, 0);

// No need (because it uses autorelease after 1.41)
//effect->release();
</pre>

<p>
Update the manager every frame.
</p>

<pre>
manager->update();
</pre>
<br>

<p>
Inherit visit and add a process to actually draw the effect.
</p>

<pre>
void HelloWorld::visit(
	cocos2d::Renderer *renderer, 
	const cocos2d::Mat4& parentTransform, 
	uint32_t parentFlags)
{
	manager->begin(renderer, _globalZOrder);
	cocos2d::Scene::visit(renderer, parentTransform, parentFlags);
	manager->end(renderer, _globalZOrder);
}
</pre>
<br>

<p>
Discard the manager at the end.
</p>

<pre>
HelloWorld::~HelloWorld()
{
	manager->release();
}
</pre>

<h3>3D</h3>

<p>Please read a sample in <b>Samples/3D/</b>. </p>

<p>You need to add a camera in cocos2d-x's Scene</p>

<pre>
auto s = Director::getInstance()->getWinSize();
camera = Camera::createPerspective(60, (GLfloat)s.width / s.height, 1, 1000);
camera->setPosition3D(Vec3(100, 100, 100));
camera->lookAt(Vec3(0, 0, 0), Vec3(0, 1, 0));
camera->setCameraFlag(cocos2d::CameraFlag::USER1);
</pre>


<p>
In addition to update the manager, you need to set camera parameters into the manager.
</p>
		
<pre>
manager->update();
manager->setCameraMatrix(camera->getViewMatrix());
manager->setProjectionMatrix(camera->getProjectionMatrix());
</pre>

<h3>Network</h3>

<p>You can edit the playing effect in an application (game etc.) via the network from the outside when application is running.</p>

<img src="img/network.png" width="800">

<p>Create an instance of server and execute makeNetworkServerEnabled with the port to be connected from Effekseer as the argument of this function. </p>

<pre>
networkSever = efk::NetworkServer::create();
networkSever->makeNetworkServerEnabled(60000);
</pre>

<p>
In addition to update the manager, you need to update the server. Then you can edit the effect from Effekseer. In order to edit the effect from another computer, it is necessary to open the port with the setting of the firewall.
</p>

<pre>
manager->update();
networkSever->update();
</pre>

		<h2>License</h2>

<p>
When using Effekseer, you need to add the following text to help etc.
</p>

<pre>
The MIT License (MIT)

Copyright (c) 2011 Effekseer Project

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
</pre>

<h2>Change log</h2>

<h3>1.52b (20/05/02)</h3>
<p>Fixed a bug where particles are not shown with Line of SpawnMethod</p>

<h3>1.52a (20/04/28)</h3>
<p>Fixed a bug that a behavior of rotated billboard is something wrong when an angle is about 90 degree</p>

<h3>1.52 (20/04/25)</h3>
<p>Various bug fixes, including crashes.</p>

<h3>1.50 (20/03/18)</h3>
<p>Supported cocos2d-x v4</p>
<p>Fixed many bugs</p>

<h3>1.43c (19/09/16)</h3>
<p>fixed a bug which causes crash if PlayOnEnter is false, and call play after next frame</p>
<p>fixed a bug that parameters are not applied which are assigned before playing</p>

<h3>1.43b (19/08/03)</h3>
<p>Fixed OpenGL blend bug</p>
<p>Fixed Samples</p>

<h3>1.43 (19/03/02)</h3>
<p>Added network functions</p>

<h3>1.42 (19/02/08)</h3>
<p>Added image caching function</p>
<p>Added documentation</p>
<p>Fixed bug that the behavior of the ribbon and track generated with the 0th frame is wrong</p>
<p>Fixed bug that SSE buffer overrun crashes</p>
<p>Fixed bug that crashes on Android when specifying easing of color</p>

<h3>1.41 (18/11/10) </h3>
<p>Fixed a bug causes crach when setRemoveOnStop is used. Fixed memory leak in samples.</p>
<p>This release makes Effect and EffectEmitter released automatically. So you need to edit codes about release</p>

<p>1.40 (18/09/12) More functions added. Speed up with Android and iOS. Supported 3D.</p>

<p>1.30 (17/11/03) released.</p>

	</div>
</body>

</html>
